﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer.Models.WebFormDataSetTableAdapters;
using DataAccessLayer.Models;

namespace LoanOriginatingSystem
{
    public partial class HomeCustomer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ViewApplicantModel model = new ViewApplicantModel(Session["currentUser"].ToString());
            populate(model);

            ViewAppSummaryModel summary = new ViewAppSummaryModel(Session["currentUser"].ToString());
            GridAppSummary.DataSource = summary.getAppData();
            GridAppSummary.DataBind();
        }

        private void populate(ViewApplicantModel model)
        {

            lblDtlName.Text = getValue(model.custData[0].ItemArray[model.custData.NameColumn.Ordinal]);
            lblDtlDOB.Text = getValue(((DateTime)(model.custData[0].ItemArray[model.custData.DOBColumn.Ordinal])).ToString("dd-MMMM-yyyy"));            
            lblDtlGender.Text = getValue(model.custData[0].ItemArray[model.custData.GenderColumn.Ordinal]);
            lblDtlAddress1.Text = getValue(model.custData[0].ItemArray[model.custData.AddressLine1Column.Ordinal]);
            lblDtlAddress2.Text = getValue(model.custData[0].ItemArray[model.custData.AddressLine2Column.Ordinal]);
            lblDtlAddress3.Text = getValue(model.custData[0].ItemArray[model.custData.AddressLine3Column.Ordinal]);
            lblDtlState.Text = getValue(model.custData[0].ItemArray[model.custData.StateCityColumn.Ordinal]);
            lblDtlPostal.Text = getValue(model.custData[0].ItemArray[model.custData.PostalCodeColumn.Ordinal]);
            lblDtlCountry.Text = getValue(model.custData[0].ItemArray[model.custData.CountryNameColumn.Ordinal]);
            lblDtlEmail.Text = getValue(model.custData[0].ItemArray[model.custData.EmailColumn.Ordinal]);
            lblDtlHomePh.Text = getValue(model.custData[0].ItemArray[model.custData.HomePhoneColumn.Ordinal]);
            lblDtlOfficePh.Text = getValue(model.custData[0].ItemArray[model.custData.OfficePhoneColumn.Ordinal]);
            lblDtlMobilePh.Text = getValue(model.custData[0].ItemArray[model.custData.MobilePhoneColumn.Ordinal]);
            lblDtlIncome.Text = getValue(model.custData[0].ItemArray[model.custData.TotalIncomeColumn.Ordinal]);
            lblDtlObligation.Text = getValue(model.custData[0].ItemArray[model.custData.OtherObligationColumn.Ordinal]);

            if (lblDtlGender.Text == "M") { lblDtlGender.Text = "Male"; }
            else if (lblDtlGender.Text == "F") { lblDtlGender.Text = "Female"; }
            
        }

        private String getValue(object row)
        {
            if (row != null) return row.ToString();
            return null;
        }


    }
}